package hadoop.mr08;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class W_stuTable implements Writable, DBWritable {
    private String id;
    private String name;
    private String sex;
    private String java;
    private String linux;
    private String political;
    private String sport;
    private String mind;
    private String compiter;
    private String english;
    private String math;


    public W_stuTable() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getJava() {
        return java;
    }

    public void setJava(String java) {
        this.java = java;
    }

    public String getLinux() {
        return linux;
    }

    public void setLinux(String linux) {
        this.linux = linux;
    }

    public String getPolitical() {
        return political;
    }

    public void setPolitical(String political) {
        this.political = political;
    }

    public String getSport() {
        return sport;
    }

    public void setSport(String sport) {
        this.sport = sport;
    }

    public String getMind() {
        return mind;
    }

    public void setMind(String mind) {
        this.mind = mind;
    }

    public String getCompiter() {
        return compiter;
    }

    public void setCompiter(String compiter) {
        this.compiter = compiter;
    }

    public String getEnglish() {
        return english;
    }

    public void setEnglish(String english) {
        this.english = english;
    }

    public String getMath() {
        return math;
    }

    public void setMath(String math) {
        this.math = math;
    }

    public W_stuTable(String id, String name, String sex, String java, String linux, String political, String sport, String mind, String compiter, String english, String math) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.java = java;
        this.linux = linux;
        this.political = political;
        this.sport = sport;
        this.mind = mind;
        this.compiter = compiter;
        this.english = english;
        this.math = math;
    }
    public void set(String id, String name, String sex, String java, String linux, String political, String sport, String mind, String compiter, String english, String math) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.java = java;
        this.linux = linux;
        this.political = political;
        this.sport = sport;
        this.mind = mind;
        this.compiter = compiter;
        this.english = english;
        this.math = math;
    }

    @Override
    public String toString() {
        return "R_stuTable{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", java='" + java + '\'' +
                ", linux='" + linux + '\'' +
                ", political='" + political + '\'' +
                ", sport='" + sport + '\'' +
                ", mind='" + mind + '\'' +
                ", compiter='" + compiter + '\'' +
                ", english='" + english + '\'' +
                ", math='" + math + '\'' +
                '}';
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(id);
        dataOutput.writeUTF(name);
        dataOutput.writeUTF(sex);
        dataOutput.writeUTF(java);
        dataOutput.writeUTF(linux);
        dataOutput.writeUTF(political);
        dataOutput.writeUTF(sport);
        dataOutput.writeUTF(mind);
        dataOutput.writeUTF(compiter);
        dataOutput.writeUTF(english);
        dataOutput.writeUTF(math);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.id = dataInput.readUTF();
        this.name = dataInput.readUTF();
        this.sex = dataInput.readUTF();
        this.java = dataInput.readUTF();
        this.linux = dataInput.readUTF();
        this.political = dataInput.readUTF();
        this.sport = dataInput.readUTF();
        this.mind = dataInput.readUTF();
        this.compiter = dataInput.readUTF();
        this.english = dataInput.readUTF();
        this.math = dataInput.readUTF();
    }

    @Override
    public void write(PreparedStatement ps) throws SQLException {
        ps.setString(1,id);
        ps.setString(2,name);
        ps.setString(3,sex);
        ps.setString(4,java);
        ps.setString(5,linux);
        ps.setString(6,political);
        ps.setString(7,sport);
        ps.setString(8,mind);
        ps.setString(9,compiter);
        ps.setString(10,english);
        ps.setString(11,math);
    }

    @Override
    public void readFields(ResultSet rs) throws SQLException {
        // 将获取的值添加给类属性
        this.id = rs.getString(1);
        this.name = rs.getString(2);
        this.sex = rs.getString(3);
        this.java = rs.getString(4);
        this.linux = rs.getString(5);
        this.political = rs.getString(6);
        this.sport = rs.getString(7);
        this.mind = rs.getString(8);
        this.compiter = rs.getString(9);
        this.english = rs.getString(10);
        this.math = rs.getString(11);
    }
}
